﻿using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOAModels;
using TarreOA.TarreOABLL;

public partial class admin_UpdateLinkman : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null)
        {
            Session["ShowMessage"] = "用户未登录，请重新登录!";
            Session["Backurl"] = "Login.aspx";
            Response.Redirect("~/Main.aspx");
        }
        else
        {
            TarreOA.TarreOAModels.User sucessUser = (User)Session["user"];
            bool userFlag = false;
            if (sucessUser.PopedomGroup.PopedomList != null)
            {
                foreach (Popedom var in sucessUser.PopedomGroup.PopedomList)
                {
                    if (var.PopedomId == 36)
                    {
                        userFlag = true;
                        break;
                    }
                }
            }
            if (!userFlag)
            {
                Session["ShowMessage"] = "用户没有该权限，请与管理员联系!";
                Session["Backurl"] = "Right.aspx";
                Response.Redirect("~/Message.aspx");
            }
        }
        if (!IsPostBack)
        {
            Linkman linkman= LinkmanManager.FindByLinkmanId(Convert.ToInt32(Request.QueryString["lid"]));
            txtClient.Text = linkman.Client.ClientName;
            txtEmail.Text = linkman.Email;
            txtFamilyAddress.Text = linkman.FamilyAddress;
            txtFamilyPostalcode.Text = linkman.FamilyPostalcode;
            txtHandsetNumber.Text = linkman.HandsetNumber;
            txtHomeTelephone.Text = linkman.HomeTelephone;
            txtJob.Text = linkman.Job;
            txtJobTelephone.Text = linkman.JobTelephone;
            txtLike.Text = linkman.Like;
            txtLinkmanName.Text = linkman.LinkmanName;
            txtQQNumber.Text = linkman.QqNumber;
            txtRemark.Text = linkman.Remark;
            hidClientId.Value = linkman.Client.ClientId.ToString();
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Linkman linkman = new Linkman();
        Client client = new Client();
        client.ClientId = Convert.ToInt32(hidClientId.Value);
        linkman.Client = client;
        linkman.Email = txtEmail.Text;
        linkman.FamilyAddress = txtFamilyAddress.Text;
        linkman.FamilyPostalcode = txtFamilyPostalcode.Text;
        linkman.HandsetNumber = txtHandsetNumber.Text;
        linkman.HomeTelephone = txtHomeTelephone.Text;
        linkman.Job = txtJob.Text;
        linkman.JobTelephone = txtJobTelephone.Text;
        linkman.Like = txtLike.Text;
        linkman.LinkmanName = txtLinkmanName.Text;
        linkman.QqNumber = txtQQNumber.Text;
        linkman.Remark = txtRemark.Text;
        linkman.Sex = Convert.ToInt32(ddlSex.SelectedValue);
        linkman.LinkmanId= Convert.ToInt32(Request.QueryString["lid"]);
        if (LinkmanManager.UpdateLinkman(linkman))
        {
            Response.Redirect("LinkmanList.aspx?pageIndex="+Request.QueryString["pageIndex"]);
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>alert('修改失败！请重试！');</script>");
        }
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("LinkmanList.aspx?pageIndex=" + Request.QueryString["pageIndex"]);
    }
}
